package com.simple.chinagpay.controller;

import com.simple.chinagpay.service.PayService;
import com.simple.chinagpay.service.TradeService;
import com.simple.common.entity.ResData;
import com.simple.common.entity.controller.VmPay;
import com.simple.common.entity.dto.pay.vm.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

/**
 * @author yasud
 * @date 2021年03月09日 09:37
 * @description
 */
@RestController
public class PayController implements VmPay {

    @Autowired
    PayService payService;

    @Autowired
    TradeService tradeService;

    @Override
    public ResData directPay(DirectPayDto directPayDto) throws Exception {
        DirectPayRspDto rspDto = payService.pay(directPayDto);
        return ResData.ok(rspDto);
    }

    @Override
    public ResData redirectPay(RedirectPayDto dto) throws IOException {
        RedirectPayRspDto rspDto = payService.redirectPay(dto);
        return ResData.ok(rspDto);
    }

    @Override
    public ResData queryTrade(QueryTradeDto dto) throws IOException {
        QueryTradeRspDto rspDto = tradeService.query(dto);
        return ResData.ok(rspDto);
    }

    @Override
    public ResData refund(RefundTradeDto dto) throws IOException {
        RefundTradeRspDto rspDto = tradeService.refund(dto);
        return ResData.ok(rspDto);
    }
}
